<?php

namespace backend\modules\bonus\controllers;

use Yii;
use common\models\base\SearchModel;
use common\traits\MerchantCurd;
use common\models\member\Member;
use common\enums\StatusEnum;
use backend\controllers\BaseController;
use common\models\bonus\Bonus;
use common\models\bonus\BonusDay;
use common\models\bonus\BonusDayMember;

use common\helpers\ExcelHelper;
use common\models\bonus\ChouJiang;
use common\models\bonus\BonusCollision;
use common\models\bonus\BonusShare;
use common\models\bonus\BonusCooperation;
use common\models\bonus\BonusShop;
use common\models\bonus\BonusYear;

use common\models\bonus\BonusMember;

use common\enums\BonusEnum;

class BonusController extends BaseController
{
    use MerchantCurd;

    /**
     * @var \yii\db\ActiveRecord
     */
    public $modelClass = Bonus::class;


    public function actionBonusSummary()
    {
        $share = BonusShare::find()->select('sum(sales) as sales, sum(bonus) as bonus, sum(tax) as tax, sum(fee) as fee, sum(bonus_real) as bonus_real')->asArray()->one();
        return $this->render($this->action->id, [
            'share' =>$share,
        ]);
    }

    public function actionList($member_id = null,$type = null)
    {
       
        $get = Yii::$app->request->get();
        $start_time = $get['start_time']??date('Y-m-d', strtotime("-1 year"));
        $end_time = $get['end_time']??date('Y-m-d', strtotime("+1 day"));
        $username = $get['username']??'';
        $searchModel = new SearchModel([
            'model' => $this->modelClass,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'username'], // 模糊查询
            'relations' => ['member' => ['realname','username']], // 关联 member 表的 nickname 字段
            'partialMatchAttributes' => ['member.realname','member.username'], // 模糊查询，注意 member_nickname 为关联表的别名 表名_字段
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        if($start_time){
             $dataProvider->query->andFilterWhere(['between', '{{%bonus}}.created_at', strtotime($start_time), strtotime($end_time)]);
        }
        // if($username){
        //     $member = Member::find()->where(['username'=>$username])->one();
        //     $dataProvider->query->andFilterWhere(['member_id'=>$member->id]);
        // }
        if($member_id){
            $dataProvider->query->andFilterWhere(['member_id'=>$member_id]);
        }

        $dataProvider->query
            ->with(['member']);

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            'username' => $username,
            'start_time' => $start_time,
            'end_time' => $end_time,
        ]);
    }

    public function actionDayList()
    {
        $searchModel = new SearchModel([
            'model' => BonusDay::class,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        $dataProvider->query;

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
        ]);
    }

    public function actionMemberDayList($day)
    {
        $searchModel = new SearchModel([
            'model' => BonusDayMember::class,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        $dataProvider->query->andWhere(['created_at'=>$day]);

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            'day' => $day,
        ]);
    }

    public function actionMemberDayInfo($day, $member_id)
    {
        $searchModel = new SearchModel([
            'model' => Bonus::class,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        $dayEndTime = $day + 86400;
        $dataProvider->query->andWhere(['member_id'=>$member_id])->andWhere(['and', ['>=','created_at',$day], ['<', 'created_at', $dayEndTime]]);

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            'day' => $day,
        ]);
    }

    /**
     * 返回模型
     *
     * @param $id
     * @return \yii\db\ActiveRecord
     */
    protected function findModel($id)
    {
        /* @var $model \yii\db\ActiveRecord */
        if (empty($id) || empty(($model = $this->modelClass::findOne(['id' => $id])))) {
            $model = new $this->modelClass;
            return $model->loadDefaultValues();
        }

        return $model;
    }
    //分享
    public function actionShareIndex()
    {
        $modelClass = BonusShare::class;
        $searchModel = new SearchModel([
            'model' => $modelClass,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        // $dayEndTime = $day + 86400;
        // $dataProvider->query->andWhere(['member_id'=>$member_id])->andWhere(['and', ['>=','created_at',$day], ['<', 'created_at', $dayEndTime]]);

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            // 'day' => $day,
        ]);
    }
    //分布
    public function actionCollisionIndex()
    {
        $modelClass = BonusCollision::class;
        $searchModel = new SearchModel([
            'model' => $modelClass,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        // $dayEndTime = $day + 86400;
        // $dataProvider->query->andWhere(['member_id'=>$member_id])->andWhere(['and', ['>=','created_at',$day], ['<', 'created_at', $dayEndTime]]);

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            // 'day' => $day,
        ]);
    }

    //合作
    public function actionCooperationIndex()
    {
        $modelClass = BonusCooperation::class;
        $searchModel = new SearchModel([
            'model' => $modelClass,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        // $dayEndTime = $day + 86400;
        // $dataProvider->query->andWhere(['member_id'=>$member_id])->andWhere(['and', ['>=','created_at',$day], ['<', 'created_at', $dayEndTime]]);

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            // 'day' => $day,
        ]);
    }
    //复消
    public function actionShopIndex()
    {
        $modelClass = BonusShop::class;
        $searchModel = new SearchModel([
            'model' => $modelClass,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        // $dayEndTime = $day + 86400;
        // $dataProvider->query->andWhere(['member_id'=>$member_id])->andWhere(['and', ['>=','created_at',$day], ['<', 'created_at', $dayEndTime]]);

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            // 'day' => $day,
        ]);
    }
    //福利
    public function actionYearIndex()
    {
        $modelClass = BonusYear::class;
        $searchModel = new SearchModel([
            'model' => $modelClass,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        // $dayEndTime = $day + 86400;
        // $dataProvider->query->andWhere(['member_id'=>$member_id])->andWhere(['and', ['>=','created_at',$day], ['<', 'created_at', $dayEndTime]]);

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            // 'day' => $day,
        ]);
    }
    public function actionBaobiao()
    {
        // $ClassArr = [BonusShare::class,BonusCollision::class,BonusCooperation::class,BonusShop::class,BonusYear::class];
        // foreach ($ClassArr as $key => $value) {
        //     # code...
        // }
        // $query = 
        //分享奖
        $fenxiang = BonusShare::find()->select('sum(sales) as sum_sales,sum(bonus) as sum_bonus,sum(tax) as sum_tax,sum(fee) as sum_fee,sum(bonus_real) as sum_bonus_real')->asArray()->one();
        //分布奖
        $fenbu = BonusCollision::find()->select('sum(sales) as sum_sales,sum(bonus) as sum_bonus,sum(tax) as sum_tax,sum(fee) as sum_fee,sum(bonus_real) as sum_bonus_real')->asArray()->one();
        //合作奖
        $hezuo = BonusCooperation::find()->select('sum(sales) as sum_sales,sum(bonus) as sum_bonus,sum(tax) as sum_tax,sum(fee) as sum_fee,sum(bonus_real) as sum_bonus_real')->asArray()->one();
        //复消奖
        $fuxiao = BonusShop::find()->select('sum(sales) as sum_sales,sum(bonus) as sum_bonus,sum(tax) as sum_tax,sum(fee) as sum_fee,sum(bonus_real) as sum_bonus_real')->asArray()->one();
        //福利奖
        $fuli = BonusYear::find()->select('sum(sales) as sum_sales,sum(bonus) as sum_bonus,sum(tax) as sum_tax,sum(fee) as sum_fee,sum(bonus_real) as sum_bonus_real')->asArray()->one();

        $result[0] = [
            'name' => '分享奖',
            'jiesuan' => $fenxiang['sum_sales']?:0,
            'jianjin' => $fenxiang['sum_bonus']?:0,
            'koushui' => $fenxiang['sum_tax']?:0,
            'guanli' => $fenxiang['sum_fee']?:0,
            'shifa' => $fenxiang['sum_bonus_real']?:0,
            'bochu' => 0,
            'xiangqing' => 'share-index',
        ];
        $result[1] = [
            'name' => '分布奖',
            'jiesuan' => $fenbu['sum_sales']?:0,
            'jianjin' => $fenbu['sum_bonus']?:0,
            'koushui' => $fenbu['sum_tax']?:0,
            'guanli' => $fenbu['sum_fee']?:0,
            'shifa' => $fenbu['sum_bonus_real']?:0,
            'bochu' => 0,
            'xiangqing' => 'collision-index',
        ];
        $result[2] = [
            'name' => '合作奖',
            'jiesuan' => $hezuo['sum_sales']?:0,
            'jianjin' => $hezuo['sum_bonus']?:0,
            'koushui' => $hezuo['sum_tax']?:0,
            'guanli' => $hezuo['sum_fee']?:0,
            'shifa' => $hezuo['sum_bonus_real']?:0,
            'bochu' => 0,
            'xiangqing' => 'cooperation-index',
        ];
        $result[3] = [
            'name' => '复消奖',
            'jiesuan' => $fuxiao['sum_sales']?:0,
            'jianjin' => $fuxiao['sum_bonus']?:0,
            'koushui' => $fuxiao['sum_tax']?:0,
            'guanli' => $fuxiao['sum_fee']?:0,
            'shifa' => $fuxiao['sum_bonus_real']?:0,
            'bochu' => 0,
            'xiangqing' => 'shop-index',
        ];
        $result[4] = [
            'name' => '福利奖',
            'jiesuan' => $fuli['sum_sales']?:0,
            'jianjin' => $fuli['sum_bonus']?:0,
            'koushui' => $fuli['sum_tax']?:0,
            'guanli' => $fuli['sum_fee']?:0,
            'shifa' => $fuli['sum_bonus_real']?:0,
            'bochu' => 0,
            'xiangqing' => 'year-index',
        ];
        $result[5] = [
            'name' => '汇总',
            'jiesuan' => $result[3]['jiesuan'] + $result[4]['jiesuan'],
            'jianjin' => $result[0]['jianjin'] + $result[1]['jianjin'] + $result[2]['jianjin']+ $result[3]['jianjin'] + $result[4]['jianjin'],
            'koushui' => $result[0]['koushui'] + $result[1]['koushui'] + $result[2]['koushui']+ $result[3]['koushui'] + $result[4]['koushui'],
            'guanli' => $result[0]['guanli'] + $result[1]['guanli'] + $result[2]['guanli']+ $result[3]['guanli'] + $result[4]['guanli'],
            'shifa' => $result[0]['shifa'] + $result[1]['shifa'] + $result[2]['shifa']+ $result[3]['shifa'] + $result[4]['shifa'],
            'bochu' => $result[0]['bochu'] + $result[1]['bochu'] + $result[2]['bochu']+ $result[3]['bochu'] + $result[4]['bochu'],
            // 'xiangqing' => '#',
        ];

        foreach ($result as $key => $value) {
            if ($value['jiesuan'] > 0) {
                $result[$key]['bochu'] = (intval($value['shifa'] / $value['jiesuan'] * 10000) / 100) . '%';

            } else {
                $result[$key]['bochu'] = '-';
            }
        }
       
        return $this->render($this->action->id, ['models'=>$result]);
    }

    public function actionShopCalc($id)
    {
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model = BonusShop::calc($id);
            $transaction->commit();
            return $this->message('结算成功', $this->redirect(['shop-index']), 'success');
        } catch (\Exception $e) {
            $transaction->rollBack();
            return $this->message($e->getMessage(), $this->redirect(['shop-index']), 'error');
        }
    }

    public function actionShopFeeCheck($id)
    {
        $model = BonusShop::feeUp($id);
        $sumModel = BonusShop::find()->where(['!=', 'id', $model->id])->select('sum(sales) as sales, sum(bonus_real) as bonus_real')->asArray()->one();
        if (!$sumModel) {
            $sumModel = [
                'sales' => 0,
                'bonus_real' => 0,
            ];
        }
        $sumModel['sales'] += $model->sales;
        $sumModel['bonus_real'] += $model->bonus_real;
        return $this->renderAjax($this->action->id, [
            'model' => $model,
            'sumModel' => $sumModel,
        ]);
    }
    
    public function actionShopFee($id)
    {
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model = BonusShop::feeUp($id, true);
            $transaction->commit();
            return $this->message('结算成功', $this->redirect(['shop-index']), 'success');
        } catch (\Exception $e) {
            $transaction->rollBack();
            return $this->message($e->getMessage(), $this->redirect(['shop-index']), 'error');
        }
    }

    public function actionShopPayment($id)
    {
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model = BonusShop::payment($id);
            $transaction->commit();
            return $this->message('释放成功', $this->redirect(['shop-index']), 'success');
        } catch (\Exception $e) {
            $transaction->rollBack();
            return $this->message($e->getMessage(), $this->redirect(['shop-index']), 'error');
        }
    }


    public function actionCollisionCalc($id)
    {
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model = BonusCollision::calc($id);
            $transaction->commit();
            return $this->message('结算成功', $this->redirect(['collision-index']), 'success');
        } catch (\Exception $e) {
            $transaction->rollBack();
            return $this->message($e->getMessage(), $this->redirect(['collision-index']), 'error');
        }
    }

    public function actionCollisionFeeCheck($id)
    {
        $model = BonusCollision::feeUp($id);
        $sumModel = BonusCollision::find()->where(['!=', 'id', $model->id])->select('sum(sales) as sales, sum(bonus_real) as bonus_real')->asArray()->one();
        if (!$sumModel) {
            $sumModel = [
                'sales' => 0,
                'bonus_real' => 0,
            ];
        }
        $sumModel['sales'] += $model->sales;
        $sumModel['bonus_real'] += $model->bonus_real;
        return $this->renderAjax($this->action->id, [
            'model' => $model,
            'sumModel' => $sumModel,
        ]);
    }
    
    public function actionCollisionFee($id)
    {
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model = BonusCollision::feeUp($id, true);
            $transaction->commit();
            return $this->message('结算成功', $this->redirect(['collision-index']), 'success');
        } catch (\Exception $e) {
            $transaction->rollBack();
            return $this->message($e->getMessage(), $this->redirect(['collision-index']), 'error');
        }
    }

    public function actionCollisionPayment($id)
    {
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model = BonusCollision::payment($id);
            $transaction->commit();
            return $this->message('释放成功', $this->redirect(['collision-index']), 'success');
        } catch (\Exception $e) {
            $transaction->rollBack();
            return $this->message($e->getMessage(), $this->redirect(['collision-index']), 'error');
        }
    } 


    public function actionCooperationFeeCheck($id)
    {
        $model = BonusCooperation::feeUp($id);
        $sumModel = BonusCooperation::find()->where(['!=', 'id', $model->id])->select('sum(sales) as sales, sum(bonus_real) as bonus_real')->asArray()->one();
        if (!$sumModel) {
            $sumModel = [
                'sales' => 0,
                'bonus_real' => 0,
            ];
        }
        $sumModel['sales'] += $model->sales;
        $sumModel['bonus_real'] += $model->bonus_real;
        return $this->renderAjax($this->action->id, [
            'model' => $model,
            'sumModel' => $sumModel,
        ]);
    }
    
    public function actionCooperationFee($id)
    {
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model = BonusCooperation::feeUp($id, true);
            $transaction->commit();
            return $this->message('结算成功', $this->redirect(['cooperation-index']), 'success');
        } catch (\Exception $e) {
            $transaction->rollBack();
            return $this->message($e->getMessage(), $this->redirect(['cooperation-index']), 'error');
        }
    }

    public function actionCooperationPayment($id)
    {
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model = BonusCooperation::payment($id);
            $transaction->commit();
            return $this->message('释放成功', $this->redirect(['cooperation-index']), 'success');
        } catch (\Exception $e) {
            $transaction->rollBack();
            return $this->message($e->getMessage(), $this->redirect(['cooperation-index']), 'error');
        }
    } 

    public function actionShareFeeCheck($id)
    {
        $model = BonusShare::feeUp($id);
        $sumModel = BonusShare::find()->where(['!=', 'id', $model->id])->select('sum(sales) as sales, sum(bonus_real) as bonus_real')->asArray()->one();
        if (!$sumModel) {
            $sumModel = [
                'sales' => 0,
                'bonus_real' => 0,
            ];
        }
        $sumModel['sales'] += $model->sales;
        $sumModel['bonus_real'] += $model->bonus_real;
        return $this->renderAjax($this->action->id, [
            'model' => $model,
            'sumModel' => $sumModel,
        ]);
    }

    public function actionShareFee($id)
    {
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model = BonusShare::feeUp($id, true);
            $transaction->commit();
            return $this->message('结算成功', $this->redirect(['share-index']), 'success');
        } catch (\Exception $e) {
            $transaction->rollBack();
            return $this->message($e->getMessage(), $this->redirect(['share-index']), 'error');
        }
    } 

    public function actionSharePayment($id)
    {
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model = BonusShare::payment($id);
            $transaction->commit();
            return $this->message('释放成功', $this->redirect(['share-index']), 'success');
        } catch (\Exception $e) {
            $transaction->rollBack();
            return $this->message($e->getMessage(), $this->redirect(['share-index']), 'error');
        }
    } 
    public function actionBonusMember($id,$type)
    {

        $modelClass = BonusMember::class;
        $searchModel = new SearchModel([
            'model' => $modelClass,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        
        $dataProvider->query->andWhere(['bonus_id'=>$id,'bonus_type'=>$type]);

        $url = Yii::$app->request->referrer;
        $title = Bonus::$typeArr[$type];
        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            'url' => $url,
            'title' => $title,
        ]);
    }
     public function actionBonusList($id,$type,$member_id)
    {

        $modelClass = Bonus::class;
        $searchModel = new SearchModel([
            'model' => $modelClass,
            'scenario' => 'default',
            // 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        
        $dataProvider->query->andWhere(['bonus_id'=>$id,'bonus_type'=>$type,'member_id'=>$member_id]);

        $url = Yii::$app->request->referrer;
        $title = Bonus::$typeArr[$type];
        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            'url' => $url,
            'title' => $title,
        ]);
    }

    public function actionOrderExport(){

        $get = Yii::$app->request->get();
        $start_time = $get['start_time'];
        $end_time = $get['end_time'];
        $query = $this->modelClass::find()
            ->alias('b')
            ->where(['b.status'=> $this->modelClass::STATUS_ISPAY])
            ->andFilterWhere(['b.bonus_type' =>$get['SearchModel']['bonus_type']])
            ->with(['member']);
        if($start_time){
            $query->andFilterWhere(['between', 'created_at', strtotime($start_time), strtotime($end_time)]);
        }
        $order =  $query->all();
        if(!$order){
            return '没有找到数据';
        }
        // [名称, 字段名, 类型, 类型规则]
        $header = [
            ['ID', 'id', 'text'],
            ['会员编号', 'username', 'text'],
            ['真实姓名', 'realname', 'text'],
            ['奖金类型', 'bonus_type', 'text'],
            ['金额', 'amount', 'text'],
            ['进入复消积分', 'fx', 'text'],
            ['进入豪车基金', 'jj', 'text'],
            ['管理费', 'glf', 'text'],
            ['提现手续费', 'tx', 'text'],
            ['实发', 'payment', 'text'],
            ['来自会员', 'from_member_id', 'text'],
            ['时间', 'created_at', 'date', 'Y-m-d H:i:s'],
            ['状态', 'status', 'text'],
            ['结算时间', 'pay_at', 'date', 'Y-m-d H:i:s'],
        ];
        foreach ($order as $key => $val) {
            $list[] = [
                    'id' => $val->id,
                    'username' => $val->member->username,
                    'realname' => $val->member->realname,
                    'bonus_type' => Bonus::$typeArr[$val->bonus_type],
                    'amount' => $val->amount,
                    'fx' => $val->fx,
                    'jj' => $val->jj,
                    'glf' => $val->glf,
                    'tx' => $val->tx,
                    'payment' => $val->payment,
                    'from_member_id' => $val->from_member_id,
                    'created_at' => $val->created_at,
                    'status' => Bonus::$statusArr[$val->status],
                    'pay_at' => $val->pay_at,
            ];
        }
        // 简单使用
      
        if($status){
            $str_title .= $this->modelClass::statusMap($status).'('.$this->modelClass::typeMap($th_type).')'.date('Y-m-d');
        }else{
            $str_title .= '奖金列表'.date('Y-m-d');
        }
        ExcelHelper::exportData($list, $header, $str_title, 'xlsx');
    }
}